<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	String url = request.getScheme() + "://" + request.getServerName()
			+ request.getRequestURI();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="<%=basePath%>" />
		<title>新增权限</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<!-- modal页固定调用 -->
		<%@ include file="/html/custom/header.jsp"%>
		<%@ include file="/html/custom/modalHeader.jsp"%>
		<style>
			#sel1,#sel2{display: none;}
		</style>
		<script type="text/javascript">
			var pope=<s:property value="jsonPope" escape="false" />;
			
		
			$(function(){
				$.validator.setDefaults({
					submitHandler: function(form) {
						 //alert("submitted!"); 
						form.submit();
					},
					highlight: function(input) {
						$(input).addClass("ui-state-highlight");
					},
					unhighlight: function(input) {
						$(input).removeClass("ui-state-highlight");
					}
			});
		
	
				$("#popeForm").validate({
					rules: {
						'popedom.popedomName': {
							required: true
						},
						'popedom.url':{
							required:true
						}
					}
				});
				
				var $selFstPope=$("#selFstPope");
				var $selSecPope=$("#selSecPope");
				
				function loadSecPope(popeId) {
					var html=["<option value='0'>请选择</option>"];
					$(pope).each(function(i,p){
						if(p['type']==2&&p['parent']==popeId){
							html.push("<option value='"+p['id']+"' >"+p['popedomName']+"</option>");
						}
					});
					$("#selSecPope").html(html.join(""));
				}
				
				$("#selFstPope").change(function() {
					loadSecPope(parseInt($(this).val(),10));
				});
				
				
				var $sel1=$("#sel1");
				var $sel2=$("#sel2");
				
				$("#selType").change(function(){
					if($(this).val()==3){
						$selFstPope.removeAttr("name");
						$selSecPope.attr("name","popedom.parent");
						$sel1.show();
						$sel2.show();
					}else if($(this).val()==2){
						$selFstPope.attr("name","popedom.parent");
						$selSecPope.removeAttr("name");
						$sel1.show();
						$sel2.hide();
					}else{
					$selFstPope.removeAttr("name");
						$selSecPope.removeAttr("name");
						$sel1.hide();
						$sel2.hide();
					}
				});
			});
		</script>
	</head>

	<body>

		<div id="content">
			<form id="popeForm" action="/swss/user/popedom_save.action"
				target="_top" method="post">
				<fieldset>
					<p>
						<label for="name">
							权限级别
						</label>
						<select  id="selType" class="sel"name="popedom.type" >
							<option value="0" >请选择</option>
							<option value="3" >3级权限</option>
							<option value="2" >2级权限</option>
							<option value="1" >1级权限</option>
						</select>
					</p>
					<p id="sel1" >
						
						
						<label for="name">
							所属1级模块
						</label>
						<select  id="selFstPope" class="sel"  >
							<option value="0" >请选择</option>
							<s:iterator value="#request.popeList" id="pope" >								
								<s:if test="type==1">
									<option  value="<s:property  value="#pope.id" />" <s:if test="id==p1">selected="selected"</s:if> >
										<s:property value="popedomName"  />
									</option>
								</s:if>
							</s:iterator>
						</select>
					</p>
					
					<p id="sel2">
						
						<label for="name">
							所属2级模块
						</label>
						<select  id="selSecPope" class="sel" >
							<option value="0" >请选择</option>
						</select>
					</p>
					
					<p>
						<label>
							权限名称
						</label>
						<input type="text" name="popedom.popedomName" 
							value="<s:property value="popedom.popedomName" />" class="ui-widget-content ui-corner-all txt" />
					</p>
					<p>
						<label>
							URL
						</label>
						<input type="text" name="popedom.url" value="<s:property value="popedom.url" />"
							class="ui-widget-content ui-corner-all txt" />
					</p>
					<p>
						<label>
							序号
						</label>
						<input type="text" name="popedom.queue" value="<s:property value="popedom.queue" />"
							class="ui-widget-content ui-corner-all txt" />
					</p>
					<p class="p2" >
						<label for="password">
							权限描述
						</label>
						<textarea name="popedom.description" id="txtDescription" rows="4" class="ui-widget-content ui-corner-all txt"
							cols=""></textarea>
					</p>
				</fieldset>

			</form>



		</div>


		<!-- modal也固定页尾 （按钮） -->
		<div class="btnset clearfix">
			<a id="btnClose" href="#">取消</a>
			<a id="btnSave" href="<s:property value="url" />">保存</a>
		</div>

	</body>
</html>
